import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Test2 {

    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<Integer> queue = new LinkedBlockingQueue<>();
        Thread t1 = new Thread(()->{//负责入队操作
            for (int i = 0; i < 5000; i++) {
                try {
                    queue.put(i);
                    System.out.println("入队："+i);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread t2 = new Thread(()->{//负责出队操作
            for (int i = 0; i < 5000; i++) {
                try {
                    int tmp = queue.take();
                    System.out.println("出队："+tmp);
                    Thread.sleep(1000);

                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t1.start();
        t2.start();
    }
}
